import router from '@system.router'
import { PageUtil } from "@src/utils/page_util.js"
import { ReportUtil } from "@ytsdk/sdks/report_sdk/report_util.js"
import { StorageUtils } from "@ytsdk/utils/storage_util.js"

const paths = [
	"/pagesA/Main",
	"/pagesC/Knowledge",
	"/pagesC/Challenge"
]

let hideInfo = {}

export const AdPageMixin = {
	// 安装入口
	install(vm) {
		// 页面生命周期
		vm.mixin({
			async onInit() {
				let routeInfo = router.getState()
				let AdPageUtil = new PageUtil(this)
				if (this._type == "index" && (paths.includes(routeInfo.path))) {
					console.info(`页面生命周期 AdPageMixin onInit`, this._type, routeInfo.path)
					//1.初始化基础数据
					await AdPageUtil.initUserDatas();
					//2.初始化页面信息
					await AdPageUtil.initPageInfo();
					//3.初始化广告能力
					if (this.isAdControl) {
						//3.1 初始化SDK（策略、上报、广告控制器）
						await AdPageUtil.initSDK()
						//3.2 初始化弹窗(满足弹窗弹出条件)  事件：页面进入 PAGE_ENTRY
						AdPageUtil.cusEventHandle("PAGE_ENTRY")
					}

					if ($YTSDK.tacticsSDK) {
						//4.初始化返回路由配置
						AdPageUtil.initRouterConfig()
					}
					let OriginPageInfo = await StorageUtils.getItem("OriginPageInfo")



					//页面展示上报
					let data = {
						referer: OriginPageInfo.pageUrl
					}
					ReportUtil.page_show_report(data)
				}
			},
			onShow() {
				// let routeInfo = router.getState()
				// let AdPageUtil = new PageUtil(this)
				// if (this._type == "index" && (paths.includes(routeInfo.path))) {
				// 	console.info(`页面生命周期 AdPageMixin onShow`,this._type, routeInfo.path,hideInfo)
				// 	if(hideInfo){
				// 		AdPageUtil.cusEventHandle("PAGE_ENTRY")
				// 	}
				// }
			},
			onHide() {
				// let routeInfo = router.getState()
				// if (this._type == "index" && (paths.includes(routeInfo.path))) {

				// 	hideInfo = {
				// 		routePath : routeInfo.path,
				// 		time : Date.now()
				// 	}
				// 	console.info(`页面生命周期 AdPageMixin onHide`,JSON.stringify(hideInfo))
				// }

			}
		})
	}
}